package com.woniuxy.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.woniuxy.controller.form.AccountAndRoleForm;
import com.woniuxy.model.AccountRole;
import com.woniuxy.service.AccountRoleService;
import com.woniuxy.utils.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 马世亮
 * @since 2022-02-15
 */
@RestController
@RequestMapping("/accountRole")
@Api(tags = "权限-账号关系接口")
public class AccountRoleController {

    @Resource
    private AccountRoleService accountRoleService;

    @ApiOperation("授权")
    @PostMapping("savepower")
    public Result savePower(@RequestBody AccountAndRoleForm accountAndRoleForm){
        System.out.println(accountAndRoleForm);
        AccountRole accountRole = new AccountRole();
        accountRole.setRoleId(accountAndRoleForm.getRoles());
        accountRole.setAccountId(accountAndRoleForm.getAccountid());

        boolean account_id = accountRoleService.saveOrUpdate(accountRole, new QueryWrapper<AccountRole>().eq("account_id", accountAndRoleForm.getAccountid()));
        if(!account_id) return Result.fail(500,"授权失败，请稍后重试");
        return Result.success(200,"授权成功",null);
    }


}

